package com.wwwarehouse.contract.convert_to_pc;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.common.eventbus_event.CardDeskEvent;

import contract.wwwarehouse.com.contract.R;
import de.greenrobot.event.EventBus;

/**
 * Created by feng.gao on 2017/9/7.
 * 导入成功的页面，推送过来的。
 */
@Route(path = "/contract/ImportSuccessFragment")
public class ImportSuccessFragment extends BaseFragment implements View.OnClickListener {
	private String mTitle;

	@Override
	public void setTitle() {
		if (peekFragment() instanceof ImportSuccessFragment) {
			if (!TextUtils.isEmpty(mTitle) && !TextUtils.isEmpty(getZhString(mTitle))) {
				mActivity.setTitle(getZhString(mTitle));
			} else {
				mActivity.setTitle(R.string.import_with_sort_title);
			}
		}
	}

	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		return inflater.inflate(R.layout.import_success_fragment_layout, container, false);
	}

	@Override
	public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		TextView mImportNumTv = (TextView) view.findViewById(R.id.num_tv);
		view.findViewById(R.id.know_btn).setOnClickListener(this);
		view.findViewById(R.id.next_btn).setOnClickListener(this);
		//推送自动跳转过来或者是推送的点击事件过来
		if (getArguments() != null ) {
			mImportNumTv.setText(String.format("本次共导入%1$s条数据" , getArguments().getLong(Constant.KEY_INTENT_IMPORT_TOOL_PUSH_CLICK)));
		}
		if (getArguments() != null && getArguments().getString(Constant.KEY_INTENT_IMPORT_TYPE) != null) {
			mTitle = getArguments().getString(Constant.KEY_INTENT_IMPORT_TYPE);
		}
	}

	@Override
	public void requestDatas() {

	}

	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.know_btn) {
			EventBus.getDefault().post(new CardDeskEvent("clear_back_stack"));
		} else if (v.getId() == R.id.next_btn) {
			// TODO: 2017/9/7 继续下一个任务
		}
	}

	private String getZhString(String eng) {
		if (eng.equals("IMPORT_TOOL")) {
			return "导入设备信息";
		}
		if (eng.equals("IMPORT_GOODS")) {
			return "导入商品信息";
		}
		if (eng.equals("IMPORT_RS_STORE")) {
			return "导入仓储信息";
		}
		if (eng.equals("IMPORT_RS_LABOUR")) {
			return "导入劳务信息";
		}
		if (eng.equals("IMPORT_RS_SALE")) {
			return "导入供货信息";
		}
		if (eng.equals("IMPORT_RS_TRANSPORT")) {
			return "导入运输信息";
		}
		return "";
	}
}
